﻿using _RobotInspection.Attributes;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;


namespace _RobotInspection.Swagger
{
    /// <summary>
    /// Swagger 过滤器：在接口描述中追加状态标签
    /// </summary>
    public class ApiStatusOperationFilter : IOperationFilter
    {
        public void Apply(OpenApiOperation operation, OperationFilterContext context)
        {
            // 读取方法上的 ApiStatus 特性
            var statusAttr = context.MethodInfo
                .GetCustomAttributes(typeof(ApiStatusAttribute), false)
                .FirstOrDefault() as ApiStatusAttribute;

            if (statusAttr == null)
                return;

            string statusLabel = statusAttr.Status switch
            {
                ApiStatusEnum.Developing => "🚧 [开发中]",
                ApiStatusEnum.Testing => "🧪 [测试中]",
                ApiStatusEnum.Completed => "✅ [已完成]",
                ApiStatusEnum.Deprecated => "❌ [已废弃]",
                _ => string.Empty
            };

            // 把状态加在 summary 前面
            operation.Summary = $"{statusLabel} {operation.Summary}";
        }
    }
}
